<template>
  <div class="app-container bg">
    <!-- 第一步和第二步组件 -->
    <Step1 
      v-show="step == 1"
      ref="step1"
      @resetform="resetform"
      :taskVideo="taskVideo"
      @changeStep="changeStep">
    </Step1>
    <!-- 第三步组件 -->
    <Step2 
      v-show="step == 2" 
      :taskVideo="taskVideo"
      @resetform="resetform"
      @changeStep="changeStep"></Step2>
  </div>
</template>

<script>
import Preview from "./components/Preview";
import { getInitTask,getTask } from "@/api/content/task";
import Step1 from "./components/Step1.vue";
import Step2 from "./components/Step2.vue";
export default {
  name: "VideoMake",
  dicts: ['sys_normal_disable','text_length'],
  components: {
    Preview,
    Step1,
    Step2
  },
  data() {
    return {
      step:1,
      taskVideo:{
        videoContent:'',
        elementIds:[],
        sequence:[]
      }
    };
  },
  watch: {

  },
  created() {
  },
  mounted() {
    this.$refs.step1.init()
    if(this.$route.query.id){
      this.getTask(this.$route.query.id)
    }else{
      this.getInitTask()
    }
    // this.getAudienceList()
    // this.getStrategyList()
    // this.getFactorsList()
    // this.getSwiper()
    // this.getAudioTemplate()
    // this.setBackfill()
  },
  methods: {
    // 切换步骤
    changeStep(step) {
      this.step = step;
      console.log(this.taskVideo)
    },
     // 创建任务工作目录
     async getInitTask(){
      const res = await getInitTask({type:'VIDEO'})
      console.log(res,'工作目录')
      // this.taskVideo = res.data.taskVideo
      this.taskVideo = res.data.taskVideo
      this.workDir = res.data.workDir
      this.$set(this.taskVideo, 'elementIds', [])
      this.$set(this.taskVideo, 'sequence', [])
    },
    // 获取任务详情
    async getTask(id){
      const res = await getTask(id)
      console.log(res,'详情');
      this.taskVideo = res.data.taskVideo
      this.taskVideo.audienceId = Number(this.taskVideo.audienceId)
      this.taskVideo.length = String(this.taskVideo.length)
      // this.taskVideo.elementIds = this.taskVideo.elementId.split(',');
      this.$set(this.taskVideo, 'elementIds', this.taskVideo.elementId?this.taskVideo.elementId.split(','):[])
      // this.editorForm.title = res.data.taskNews.title
      // this.editorForm.content = res.data.taskNews.content
    },
    // 重置数据
    resetform(){
      this.step = 1
      this.getInitTask()
    }
  }
};
</script>
<style lang="scss" scoped>

</style>